import {Injectable} from "@angular/core";

@Injectable()
export class CacheService {
  private _data: { [key: string]: any } = {};
  globalPrefix: string = "";

  public getItem(key: string) {
    return this._data[this.buildCacheKey(key)] ? this._data[this.buildCacheKey(key)] : null;
  }

  public setItem(key: string, value: any) {
    this._data[this.buildCacheKey(key)] = value;
    return true;
  }

  public removeItem(key: string) {
    delete this._data[this.buildCacheKey(key)];
  }

  public clear() {
    this._data = [];
  }

  public setGlobalPrefix(prefix: string): void {
    this.globalPrefix = prefix;
  }

  private buildCacheKey(key: string): string {
    return this.globalPrefix + key;
  }


}



